# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : largest_number.py
# @Time     : 2024/2/17 23:10
# @Author   : Robot-Zsj
"""
description: 
"""


def largest_number(nums):
    nums = [str(i) for i in nums]
    for i in range(len(nums) - 1):
        for j in range(i + 1, len(nums)):
            if int(nums[i] + nums[j]) < int(nums[j] + nums[i]):
                nums[i], nums[j] = nums[j], nums[i]
    if int(''.join(nums)) == 0:
        return str(0)
    else:
        return ''.join(nums)


print(largest_number([2, 30]))


def largest_number_2(nums):
    from functools import cmp_to_key
    nums = sorted([str(i) for i in nums], key=cmp_to_key(lambda x, y: int(y + x) - int(x + y)))
    if int(''.join(nums)) == 0:
        return str(0)
    else:
        return ''.join(nums)


print(largest_number_2([2, 30]))
